package me.chanjar.weixin.component.bean.author;

import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Lists;

/**
 * 获取授权方的帐号基本信息结果
 * 
 * @author Debenson
 * @since 0.1
 */
public class WxGetAuthorizerInfoResult implements Serializable {
  private static final long serialVersionUID = -8127109605037465083L;

  /** 授权方信息 */
  @JsonProperty("authorizer_info")
  private WxAuthorizerInfo authorizerInfo;

  /** 授权信息 */
  @JsonProperty("authorization_info")
  private WxAuthorizationInfo authorizationInfo;

  /**
   * 是否为小程序授权
   * 
   * @return
   */
  @JsonIgnore
  public boolean isWxApp() {
    return authorizerInfo != null && authorizerInfo.getMiniProgramInfo() != null;
  }

  /**
   * 是否公众号授权
   * 
   * @return
   */
  @JsonIgnore
  public boolean isMp() {
    return !isWxApp();
  }

  public WxAuthorizerInfo getAuthorizerInfo() {
    return authorizerInfo;
  }

  public void setAuthorizerInfo(WxAuthorizerInfo authorizerInfo) {
    this.authorizerInfo = authorizerInfo;
  }

  public WxAuthorizationInfo getAuthorizationInfo() {
    return authorizationInfo;
  }

  public void setAuthorizationInfo(WxAuthorizationInfo authorizationInfo) {
    this.authorizationInfo = authorizationInfo;
  }

  public static class WxAuthorizerInfo implements Serializable {
    private static final long serialVersionUID = -4462920723411244702L;

    @JsonProperty("nick_name")
    private String nickName;

    @JsonProperty("head_img")
    private String headImg;

    @JsonProperty("service_type_info")
    private WxServiceTypeInfo serviceTypeInfo;

    @JsonProperty("verify_type_info")
    private WxVerifyTypeInfo verifyTypeInfo;

    @JsonProperty("user_name")
    private String userName; // 授权方公众号的原始ID

    @JsonProperty("principal_name")
    private String principalName; // 公众号的主体名称

    @JsonProperty("business_info")
    private WxBusinessInfo businessInfo;

    private String alias;

    @JsonProperty("qrcode_url")
    private String qrcodeUrl;

    /** 小程序帐号介绍 */
    private String signature;

    /** 可根据这个字段判断是否为小程序类型授权 */
    @JsonProperty("MiniProgramInfo")
    private WxMiniProgramInfo miniProgramInfo;

    public WxMiniProgramInfo getMiniProgramInfo() {
      return miniProgramInfo;
    }

    public void setMiniProgramInfo(WxMiniProgramInfo miniProgramInfo) {
      this.miniProgramInfo = miniProgramInfo;
    }

    public String getNickName() {
      return nickName;
    }

    public void setNickName(String nickName) {
      this.nickName = nickName;
    }

    public String getHeadImg() {
      return headImg;
    }

    public void setHeadImg(String headImg) {
      this.headImg = headImg;
    }

    public WxServiceTypeInfo getServiceTypeInfo() {
      return serviceTypeInfo;
    }

    public void setServiceTypeInfo(WxServiceTypeInfo serviceTypeInfo) {
      this.serviceTypeInfo = serviceTypeInfo;
    }

    public WxVerifyTypeInfo getVerifyTypeInfo() {
      return verifyTypeInfo;
    }

    public void setVerifyTypeInfo(WxVerifyTypeInfo verifyTypeInfo) {
      this.verifyTypeInfo = verifyTypeInfo;
    }

    public String getUserName() {
      return userName;
    }

    public void setUserName(String userName) {
      this.userName = userName;
    }

    public String getPrincipalName() {
      return principalName;
    }

    public void setPrincipalName(String principalName) {
      this.principalName = principalName;
    }

    public WxBusinessInfo getBusinessInfo() {
      return businessInfo;
    }

    public void setBusinessInfo(WxBusinessInfo businessInfo) {
      this.businessInfo = businessInfo;
    }

    public String getAlias() {
      return alias;
    }

    public void setAlias(String alias) {
      this.alias = alias;
    }

    public String getQrcodeUrl() {
      return qrcodeUrl;
    }

    public void setQrcodeUrl(String qrcodeUrl) {
      this.qrcodeUrl = qrcodeUrl;
    }

    public String getSignature() {
      return signature;
    }

    public void setSignature(String signature) {
      this.signature = signature;
    }

    public static class WxServiceTypeInfo implements Serializable {
      private static final long serialVersionUID = -7167937077621818462L;
      private Integer id;

      public Integer getId() {
        return id;
      }

      public void setId(Integer id) {
        this.id = id;
      }
    }

    public static class WxVerifyTypeInfo implements Serializable {
      private static final long serialVersionUID = -6486326535360686561L;
      private Integer id;

      public Integer getId() {
        return id;
      }

      public void setId(Integer id) {
        this.id = id;
      }
    }

    public static class WxBusinessInfo implements Serializable {
      private static final long serialVersionUID = -812330953161955013L;

      @JsonProperty("open_store")
      private Integer openStore; // 是否开通微信门店功能

      @JsonProperty("open_scan")
      private Integer openScan; // 是否开通微信扫商品功能

      @JsonProperty("open_pay")
      private Integer openPay; // 是否开通微信支付功能

      @JsonProperty("open_card")
      private Integer openCard; // 是否开通微信卡券功能

      @JsonProperty("open_shake")
      private Integer openShake; // 是否开通微信摇一摇功能

      public Integer getOpenStore() {
        return openStore;
      }

      public void setOpenStore(Integer openStore) {
        this.openStore = openStore;
      }

      public Integer getOpenScan() {
        return openScan;
      }

      public void setOpenScan(Integer openScan) {
        this.openScan = openScan;
      }

      public Integer getOpenPay() {
        return openPay;
      }

      public void setOpenPay(Integer openPay) {
        this.openPay = openPay;
      }

      public Integer getOpenCard() {
        return openCard;
      }

      public void setOpenCard(Integer openCard) {
        this.openCard = openCard;
      }

      public Integer getOpenShake() {
        return openShake;
      }

      public void setOpenShake(Integer openShake) {
        this.openShake = openShake;
      }

    }

    /**
     * 小程序信息, 可根据这个字段判断是否为小程序类型授权
     * 
     * @author Debenson
     * @since 0.1
     */
    public static class WxMiniProgramInfo implements Serializable {
      private static final long serialVersionUID = 4260213458927939408L;

      private WxNetwork network;
      private List<WxCategory> categories;
      @JsonProperty("visit_status")
      private Integer visitStatus;

      public WxNetwork getNetwork() {
        return network;
      }

      public void setNetwork(WxNetwork network) {
        this.network = network;
      }

      public List<WxCategory> getCategories() {
        return categories;
      }

      public void setCategories(List<WxCategory> categories) {
        this.categories = categories;
      }

      public Integer getVisitStatus() {
        return visitStatus;
      }

      public void setVisitStatus(Integer visitStatus) {
        this.visitStatus = visitStatus;
      }

      public static class WxNetwork implements Serializable {
        private static final long serialVersionUID = 6735726903297995913L;

        @JsonProperty("RequestDomain")
        private List<String> requestDomains;
        @JsonProperty("WsRequestDomain")
        private List<String> wsrequestDomains;
        @JsonProperty("UploadDomain")
        private List<String> uploadDomains;
        @JsonProperty("DownloadDomain")
        private List<String> downloadDomains;

        public WxNetwork addRequestDomains(String... domains) {
          if (requestDomains == null) {
            requestDomains = Lists.newArrayList();
          }
          requestDomains.addAll(Lists.newArrayList(domains));
          return this;
        }

        public WxNetwork addWsrequestDomains(String... wsdomains) {
          if (wsrequestDomains == null) {
            wsrequestDomains = Lists.newArrayList();
          }
          wsrequestDomains.addAll(Lists.newArrayList(wsdomains));
          return this;
        }

        public WxNetwork addUploadDomains(String... domains) {
          if (uploadDomains == null) {
            uploadDomains = Lists.newArrayList();
          }
          uploadDomains.addAll(Lists.newArrayList(domains));
          return this;
        }

        public WxNetwork addDownloadDomains(String... domains) {
          if (downloadDomains == null) {
            downloadDomains = Lists.newArrayList();
          }
          downloadDomains.addAll(Lists.newArrayList(domains));
          return this;
        }

        public List<String> getRequestDomains() {
          return requestDomains;
        }

        public void setRequestDomains(List<String> requestDomains) {
          this.requestDomains = requestDomains;
        }

        public List<String> getWsrequestDomains() {
          return wsrequestDomains;
        }

        public void setWsrequestDomains(List<String> wsrequestDomains) {
          this.wsrequestDomains = wsrequestDomains;
        }

        public List<String> getUploadDomains() {
          return uploadDomains;
        }

        public void setUploadDomains(List<String> uploadDomains) {
          this.uploadDomains = uploadDomains;
        }

        public List<String> getDownloadDomains() {
          return downloadDomains;
        }

        public void setDownloadDomains(List<String> downloadDomains) {
          this.downloadDomains = downloadDomains;
        }

      }

      public static class WxCategory implements Serializable {
        private static final long serialVersionUID = 4144357476939270353L;

        private String first;
        private String second;

        public String getFirst() {
          return first;
        }

        public void setFirst(String first) {
          this.first = first;
        }

        public String getSecond() {
          return second;
        }

        public void setSecond(String second) {
          this.second = second;
        }

      }
    }
  }

  public static class WxAuthorizationInfo implements Serializable {
    private static final long serialVersionUID = 5438767229902602051L;

    @JsonProperty("authorizer_appid")
    private String authorizerAppid;

    @JsonProperty("func_info")
    private List<WxFuncInfo> funcInfo;

    public String getAuthorizerAppid() {
      return authorizerAppid;
    }

    public void setAuthorizerAppid(String authorizerAppid) {
      this.authorizerAppid = authorizerAppid;
    }

    public List<WxFuncInfo> getFuncInfo() {
      return funcInfo;
    }

    public void setFuncInfo(List<WxFuncInfo> funcInfo) {
      this.funcInfo = funcInfo;
    }

  }

}
